<template>
  <div class="container">
    <PropTable
      :columns="column"
      :data="list"
      :total="total"
      @handleSizeChange="handleSizeChange"
      @handleCurrentChange="handleCurrentChange"
      class="dailt-table"
    >
      <template v-slot:meetingState="scope">
        <el-tag :type="typeColor(scope.row.meetingState)">
          {{ scope.row.meetingState }}
        </el-tag>
      </template>

      <template v-slot:createTime="scope">
        <div v-if="!useEmpty(scope.row.createTime)">
          {{ formatDate(scope.row.createTime) }}
        </div>
      </template>

      <template v-slot:operation="scope">
        <el-button
          type="primary"
          link
          v-if="scope.row.meetingState === '未进行'"
          icon="Edit"
          @click="importHistory(scope.row)"
        >
          导入记录
        </el-button>

        <el-button
          type="primary"
          link
          v-if="scope.row.meetingState === '已完成'"
          icon="Message"
          @click="meetingHistory(scope.row)"
        >
          会议记录
        </el-button>

        <el-button
         v-if="scope.row.meetingState === '已完成' || userStore.rolescode==15"
          link
          type="primary"
          @click="handleDetails(scope.row)"
        >
          详情
        </el-button>
      </template>
      <template #btn>
        <div
          style="
            display: flex;
            justify-content: space-between;
            align-items: center;
          "
        >
          <h1>我的会议</h1>
          <el-button type="primary" v-if="userStore.rolescode!=15" @click="meberReport"> 新建会议通知 </el-button>
        </div>
      </template>
    </PropTable>
  </div>
</template>
<script setup>
import { ref, onMounted } from "vue";
import PropTable from "@/components/Table/PropTable/index.vue";
import { useRouter } from "vue-router";
import { useEmpty, formatDate } from "@/utils/index";
import {
  meetingListApi,
  meetingFilesApi,
  importHstriy,
  fileUploadApi,
} from "@/api/meeting/index";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
const list = ref([]);
let pageNum = ref(1);
let pageSize = ref(10);
let total = ref(0);
const router = useRouter();
const props = defineProps({
  activeIndex: {
    type: Number,
    required: true,
  },
});
const column = ref([
  {
    name: "meetingTime",
    label: "会议时间",
  },
  {
    name: "nickName",
    label: "发起人",
  },

  {
    name: "meetingName",
    label: "会议名称",
  },
  { name: "meetingState", label: "状态", slot: true },
  { name: "operation", slot: true, fixed: "right", width: 300, label: "操作" },
]);
// 标签颜色
const typeColor = (val) => {
  if (val && val === "已完成") {
    return "primary";
  } else {
    return "warning";
  }
};
// 导入会议跳转页面
const meberReport = () => {
  router.push({
    path: "/myProject/information-info/addMeeting",
        query: { name:1 },
  });
};
const button1Color = ref(false);
const button2Color = ref(false);
// 获取会议列表
const getMeetingLiat = async () => {
  let params = {
    pageNum: pageNum.value,
    pageSize: pageSize.value,
  };
  const res = await meetingListApi(params);
  if (res.code === 200) {
    list.value = res.rows;
    total.value = res.total;
  }
};
// 切换每页条数
const handleSizeChange = async (valueSise) => {
  pageSize.value = valueSise;
  getMeetingLiat();
};
// 切换页码
const handleCurrentChange = async (valuePage) => {
  pageNum.value = valuePage;
  getMeetingLiat();
};
// 导入记录
const importHistory = async (row) => {
  router.push({
    path: "/myProject/information-info/addfile",
    query: { id: row.meetingUuid,name:1},
  });
};

// 详情
const handleDetails = async (row) => {
  router.push({
    path: "/myProject/information-info/addfile",
    query: { id: row.meetingUuid ,name:3},
  });
};

// const historyList = ref([]);
const { proxy } = getCurrentInstance();
// 会议记录
const meetingHistory = async (row) => {
  let id = row.meetingUuid;
  const res = await meetingFilesApi(id);
  if (res.code === 200) {
    const historyList = res.data.map((item) => item.fileUuid);
    let fileValues = historyList && historyList.join(",");
    proxy.$download.zip("/common/bantchDownload/fileIds?fileIds=" + fileValues);
  }
};

onMounted(async () => {
  button1Color.value = true;
  await getMeetingLiat();
  setTimeout(() => {}, 500);
});
</script>
<style lang="scss" scoped>
.container {
  padding: 0px 20px;
  // margin-bottom:20px;
}
.title {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.dailt-table {
  // height: 80vh;
  // max-height: 100vh;
}
</style>
